package com.ruoyi.common.core.utils;

import com.alibaba.fastjson2.JSON;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.tea.TeaException;
import com.aliyun.teautil.models.RuntimeOptions;
import com.google.gson.Gson;
import com.ruoyi.common.core.domain.Code;

public class SendMessUtil {

    public static void sendMess(String phone,String code) throws Exception {
        com.aliyun.dysmsapi20170525.Client client = SmsUtil.createClient();
        com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
                .setPhoneNumbers(phone)
                .setSignName("阿里云短信测试")
                .setTemplateCode("SMS_154950909")
                .setOutId("1773121965785135")
                .setTemplateParam(JSON.toJSONString(new Code(code)));

        // 复制代码运行请自行打印 API 的返回值
        SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, new RuntimeOptions());
        System.out.println(sendSmsResponse.getBody().message);
        System.out.println(new Gson().toJson(sendSmsResponse.body));
    }
}
